//
//  HREvaluateCell.m
//  haierapp
//
//  Created by gaotangzhang on 14-8-25.
//  Copyright (c) 2014年 haier. All rights reserved.
//

#import "HREvaluateCell.h"

#import "HREvaluateInfo.h"


#define HEIGHT_IMAGE 55.0f

@implementation HREvaluateCell

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(id)init{
    self=[[[NSBundle mainBundle]loadNibNamed:@"HREvaluateCell" owner:self options:nil]objectAtIndex:0];
    
    return self;
}

-(void)configWithData:(id)data{
    HREvaluateInfo *info=(HREvaluateInfo *)data;
    
    self.contentLabel.text=info.content;
    self.paramLabel.text=@"";
    
    //循环参数
    if ([info.productClassify count]>0) {
        for (HRProSpeInfo *speInfo in info.productClassify) {
            NSString *paramStr=self.paramLabel.text;
            self.paramLabel.text=[NSString stringWithFormat:@"%@%@:%@;",paramStr,speInfo.name,speInfo.value];
        }
    }else{
        self.paramLabel.hidden=YES;
    }
    
    
    self.userNameLabel.text=info.userName;
    self.dateLabel.text=info.evaluateDate;
    
    
    //set image
    for (UIImageView *imageView in self.imageArray) {
        [imageView setImage:nil];
    }
    
    
    NSLayoutConstraint *heightCons;
    NSLayoutConstraint *paddingTopCons;
    
    //获取PaddingTop值
    for (NSLayoutConstraint *constraint in self.constraints) {
        if (constraint.firstItem==self.imageContentView && constraint.firstAttribute==NSLayoutAttributeTop) {
            paddingTopCons=constraint;
            break;
        }
    }
    
    //获取imageContentView的高度
    for (NSLayoutConstraint *constraint in self.imageContentView.constraints) {
        if(constraint.firstItem==self.imageContentView && constraint.firstAttribute==NSLayoutAttributeHeight){
            heightCons=constraint;
            break;
        }
    }
  
    if ([info.sdPhoto count]==0 || info.sdPhoto==nil) {
        [self.imageContentView setHidden:YES];
        paddingTopCons.constant=0.0f;
        heightCons.constant=0.0f;
    }else{
        self.imageContentView.hidden=NO;
        paddingTopCons.constant=10.0f;
        heightCons.constant=HEIGHT_IMAGE;
        
        for (int i=0; i<[info.sdPhoto count] && i<5; i++) {
            HRGoodsImageInfo *imageInfo=[info.sdPhoto objectAtIndex:i];
            UIImageView *imageView=[self.imageArray objectAtIndex:i];
            NSURL *imageUrl=[NSURL URLWithString:imageInfo.link];
            [imageView setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:IMAGENAME_PLACE_HODLE]];
        }
    }
}

@end
